const util = require("../../../utils/util");

// pages/clause/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbar_bgcolor: wx.getStorageSync('navbar_bgcolor'),
    btnText: '同意条款',
    disabled: true, //是否可用
    counttime: 8,
    agreen: false,
    userName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userName = options.userName;
    this.setData({
      userName: userName
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    this.countDown(that, 5);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  next: function () {
    if (this.data.agreen == true) {
      wx.navigateTo({
        url: '/pages/refund/index/index?userName=' + this.data.userName,
      })
    } else {
      util.showInfoToast('请选择同意条款');
    }
  },
  //定时器
  countDown: function (that, count) {

    if (count == 0) {
      that.setData({
        counttime: count,
        disabled: false,
        btnText: '同意条款，开始报名'
      })
      return;
    }
    that.setData({
      counttime: count,
      btnText: count + 's后继续'
    })
    setTimeout(function () {
      count--;
      that.countDown(that, count);
    }, 1000);
  },
  checkboxChange: function (e) {
    var checkedArr = e.detail.value;
    if (checkedArr.length != 0) {
      this.setData({
        agreen: true
      })
    }
  }
})